import { Table as AntTable } from 'antd';
import { ReactNode } from 'react';
import DelButton from './delbutton';
import Shadow from './shadow';
import Index from './index';
import Op from './op';

function Table<T extends object>({
	data,
	idfieldname,
	children,
	render,
	opwidth,
	index = true
}: {
	data: T[];
	idfieldname: keyof T;
	children: ReactNode;
	render?(record: T): ReactNode;
	opwidth?: string;
	index?: boolean;
}) {
	return <>
		<Shadow>
			<AntTable<T>
				rowKey={(r) => {
					return r[idfieldname] as unknown as string;
				}}
				bordered
				dataSource={data}
				pagination={false}
			>
				{index && Index()}
				{children}
				{render && Op<T>(idfieldname, render, opwidth)}
			</AntTable>
		</Shadow>
	</>;
}

Table.Column = AntTable.Column;
export default Table;
